<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>表格Demo</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../assets/libs/layui/css/layui.css" media="all">
</head>

<body>


    <form class="layui-form" action="" lay-filter="example" method="POST" action="" style="padding: 20px 10px;">

        <div class="layui-form-item">
            <label class="layui-form-label">起始位置</label>
            <div class="layui-input-block">
                <input type="text" name="startRegion" id="startRegion" lay-verify="required" placeholder="请输入" required
                    autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">终点位置</label>
            <div class="layui-input-block">
                <input type="text" name="endRegion" id="endRegion" lay-verify="required" placeholder="请输入" required
                    autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">高铁日期</label>
            <div class="layui-input-block">
                <input name="speedDate" id="speedDate" required lay-verify="required" placeholder="请输入" required
                    class="layui-input"></input>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">高铁时间</label>
            <div class="layui-input-block">
                <input name="speedTime" id="speedTime" required lay-verify="required" placeholder="请输入" required
                    class="layui-input"></input>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">票价</label>
            <div class="layui-input-block">
                <input type="number" name="speedMon" id="speedMon" lay-verify="required" placeholder="请输入" required
                    autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">车厢数目</label>
            <div class="layui-input-block">
                <input type="number" name="speedSection" id="speedSection" lay-verify="required" placeholder="请输入"
                    required autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">车厢座位排数</label>
            <div class="layui-input-block">
                <input type="number" name="speedRow" id="speedRow" lay-verify="required" placeholder="请输入" required
                    autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" style="margin: auto;">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="submit" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <style>
        label.layui-form-label {
            width: 90px;
        }

        div.layui-input-block {
            margin-left: 125px;
        }
    </style>
    <script src="../../assets/libs/layui/layui.js" charset="utf-8"></script>
    <script>

        layui.config({
            base: '/module/'
        }).extend({

        }).use(['upload', 'config', 'form', 'jquery', 'laydate'], function () {
            var config = layui.config;
            var form = layui.form;
            var $ = layui.jquery;
            var laydate = layui.laydate;

            laydate.render({
                elem: '#speedDate',
                value: new Date()
                , type: 'date'
                , trigger: 'click'
            });

            laydate.render({
                elem: '#speedTime',
                value: new Date()
                , type: 'time'
                , trigger: 'click'
                , format: 'HH:mm'
            });


            $('#submit').on('click', function () {
                var data = form.val('example');

                $.ajax({
                    type: "POST",
                    url: config.base_server + "addSpeed",
                    data: data,
                    success: function (data) {
                        if (data.code == 1) {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            alert("添加成功");
                            parent.layer.close(index); //再执行关闭   
                        } else {
                            alert(data.msg);
                        }
                    },
                    error() {

                    }
                });
                return false;
            });
        })
    </script>


</body>